function formatRelativeTime(date) {
    const now = new Date()
    const diff = Math.abs(now - date)
    const minutes = Math.round(diff / (1000 * 60))
    const hours = Math.round(minutes / 60)

    if (minutes === 1) {
        return '1分钟前'
    } else if (minutes >= 30 && minutes < 60) {
        return '半小时前'
    } else if (hours >= 1 && hours < 2) {
        return '1小时前'
    } else if (hours >= 2 && hours < 3) {
        return '2小时前'
    } else if (hours >= 3 && hours < 4) {
        return '3小时前'
    } else if (hours >= 4 && hours < 12) {
        return '4小时前'
    } else if (hours >= 12 && hours < 24) {
        return '12小时前'
    } else if (hours >= 24 && hours < 24) {
        return '1天前'
    } else if (hours === 24 && hours < 36) {
        return '2天前'
    } else {
        // 你可以根据需要添加更多的条件来处理其他时间差
        var dateString = new Date(date)
        var year = dateString.getFullYear()
        var month = ('0' + (dateString.getMonth() + 1)).slice(-2) // 月份是从0开始的，所以加1
        var day = ('0' + dateString.getDate()).slice(-2) // 获取日，并转换为两位数
        return year + '-' + month + '-' + day
    }
}

// 时间格式化
function formatDate(date) {
    var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear(),
        hours = d.getHours(),
        minutes = d.getMinutes(),
        seconds = d.getSeconds()

    if (month.length < 2) month = '0' + month
    if (day.length < 2) day = '0' + day
    if (hours.length < 2) hours = '0' + hours
    if (minutes.length < 2) minutes = '0' + minutes
    if (seconds.length < 2) seconds = '0' + seconds

    return [year, month, day].join('-') + ' ' + [hours, minutes, seconds].join(':')
}

// s时间格式化
function formatDateToYYYYMMDD(dateString) {
    var date = new Date(dateString)
    var year = date.getFullYear()
    var month = ('0' + (date.getMonth() + 1)).slice(-2) // 月份是从0开始的，所以加1
    var day = ('0' + date.getDate()).slice(-2) // 获取日，并转换为两位数
    return year + '-' + month + '-' + day
}

// s时间格式化
function formatDateToMMDD(dateString) {
    var date = new Date(dateString)
    var year = date.getFullYear()
    var month = ('0' + (date.getMonth() + 1)).slice(-2) // 月份是从0开始的，所以加1
    var day = ('0' + date.getDate()).slice(-2) // 获取日，并转换为两位数
    return month + '月' + day
}

// 字符串根据逗号分隔
function stringSplitToArr(text) {
    return text.split(',')
}

// 处理活动等级
function typeActive(type) {
    if (type === 0) {
        return '院级'
    } else if (type === 1) {
        return '校级'
    } else if (type === 2) {
        return '社团'
    }
}
// 活动状态处理
function statusActive(status) {
    if (status === 0) {
        return '审核中'
    }
    else if (status === 1) {
        return '报名中'
    }
    else if (status === 2) {
        return '报名截止'
    }
    else if (status === 3) {
        return '已结束'
    }
}

export default {
    formatRelativeTime,
    formatDate,
    stringSplitToArr,
    formatDateToMMDD,
    formatDateToYYYYMMDD,
    typeActive,
    statusActive
}